﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using XTools.XToolsBLLEx;
namespace XTools.App_Code
{
    public class Dll
    {
        /********************StationIO********************/

        //设置文件路径
        [DllImport("StationIO.dll")]
        public static extern void SetStationPath([MarshalAs(UnmanagedType.LPTStr)] string file_path);

        //打开文件
        [DllImport("StationIO.dll")]
        public static extern IntPtr OpenCfgs([MarshalAs(UnmanagedType.LPTStr)] string station_cfg_file);

        //读取站点
        [DllImport("StationIO.dll")]
        public static extern IntPtr ReadStation([MarshalAs(UnmanagedType.LPTStr)] string station_id, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //删除站点
        [DllImport("StationIO.dll")]
        public static extern IntPtr DeleteStation([MarshalAs(UnmanagedType.LPTStr)] string station_id, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //新增站点
        [DllImport("StationIO.dll")]
        public static extern IntPtr InsertStation([MarshalAs(UnmanagedType.LPTStr)] string station_cfg, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //关闭保存文件
        [DllImport("StationIO.dll")]
        public static extern bool CloseCfgs([MarshalAs(UnmanagedType.LPTStr)] string station_cfg_file, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //判断站点是否存在
        [DllImport("StationIO.dll")]
        public static extern bool IsStaIDExist([MarshalAs(UnmanagedType.LPTStr)] string StaID, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //获取基元、虚元数
        [DllImport("StationIO.dll")]
        public static extern IntPtr GetStationTableNum([MarshalAs(UnmanagedType.LPTStr)] string StaID, [MarshalAs(UnmanagedType.LPTStr)] string cfgs);

        //读取属性
        [DllImport("StationIO.dll")]
        public static extern IntPtr ReadCfg([MarshalAs(UnmanagedType.LPTStr)] string para_id, [MarshalAs(UnmanagedType.LPTStr)] string station_cfg);

        //批量读取属性
        [DllImport("StationIO.dll")]
        public static extern IntPtr ReadCfgList([MarshalAs(UnmanagedType.LPTStr)] string para_id, [MarshalAs(UnmanagedType.LPTStr)] string pos_list, [MarshalAs(UnmanagedType.LPTStr)] string station_cfg);

        //写入属性
        [DllImport("StationIO.dll")]
        public static extern IntPtr WriteCfg([MarshalAs(UnmanagedType.LPTStr)] string sReplaceBy, [MarshalAs(UnmanagedType.LPTStr)] string para_id, [MarshalAs(UnmanagedType.LPTStr)] string station_cfg);

        //读取站点名称、站点编号
        [DllImport("StationIO.dll")]
        public static extern IntPtr GetCfgs([MarshalAs(UnmanagedType.LPTStr)] string station_cfg_file);

        //反转数据 "低位在前 高位在后"
        [DllImport("StationIO.dll")]
        public static extern IntPtr ReviseStation([MarshalAs(UnmanagedType.LPTStr)] string station_cfg);

        /********************MixIO********************/
        //解码
        [DllImport("MixIO.dll")]
        public static extern IntPtr ExplicitMsg(int iOutputFmt, [MarshalAs(UnmanagedType.LPTStr)] string szData, [MarshalAs(UnmanagedType.LPTStr)] string szCfgs, [MarshalAs(UnmanagedType.LPTStr)] string szTable);
        [DllImport("MixIO.dll")]
        public static extern IntPtr GetFieldName([MarshalAs(UnmanagedType.LPTStr)] string szFieldID,
           [MarshalAs(UnmanagedType.LPTStr)] string szTable);
        [DllImport("MixIO.dll", EntryPoint="ReadCfg")]
        public static extern IntPtr ReadCfgEx([MarshalAs(UnmanagedType.LPTStr)] string szFieldID,
           [MarshalAs(UnmanagedType.LPTStr)] string szCfgs, [MarshalAs(UnmanagedType.LPTStr)] string szTable);
        [DllImport("MixIO.dll", EntryPoint = "WriteCfg")]
        public static extern IntPtr WriteCfgEx([MarshalAs(UnmanagedType.LPTStr)] string szNewStr, [MarshalAs(UnmanagedType.LPTStr)] string szFieldID,
           [MarshalAs(UnmanagedType.LPTStr)] string szCfgs, [MarshalAs(UnmanagedType.LPTStr)] string szTable);
        [DllImport("MixIO.dll")]
        public static extern IntPtr ReadVersion();
        [DllImport("MixIO.dll")]
        public static extern IntPtr OrderCfg([MarshalAs(UnmanagedType.LPTStr)] string szCfg,int fDoIndex);
         [DllImport("MixIO.dll")]
        public static extern int getRecPosition(ref Common.StructRecLocation dt, byte iC0, byte iCX, [MarshalAs(UnmanagedType.LPTStr)] string szCfgs, [MarshalAs(UnmanagedType.LPTStr)] string szTable);
        [DllImport("GetModifyCfg.dll")]
        public static extern IntPtr GetModifyCfgStr([MarshalAs(UnmanagedType.AnsiBStr)] string szOldCfgs, [MarshalAs(UnmanagedType.AnsiBStr)] string szNewCfgs);
        [DllImport("GetModifyCfg.dll")]
        public static extern bool CheckCmd([MarshalAs(UnmanagedType.AnsiBStr)] string szOldCfgs, [MarshalAs(UnmanagedType.AnsiBStr)] string szNewCfgs, [MarshalAs(UnmanagedType.AnsiBStr)] string szCmd);
        [DllImport("GetModifyCfg.dll")]
        public static extern int CreateCmdPack(ref byte packContent, int packLen, ref byte pHeadPack, int pageUnit, int pageIndex, int pages, byte mapType, byte bProperty, [MarshalAs(UnmanagedType.AnsiBStr)] string szCFG_CRC, [MarshalAs(UnmanagedType.AnsiBStr)] string szCFG_index);
        [DllImport("GetModifyCfg.dll")]
        public static extern int CreateReadCmdPack(int type, int pageUnit, int pageIndex, int pages, int staId,
    int op, byte mapType, ref byte pHeadPack, ref byte pContentPack);
    }
}